package com.slipper.system.schedule;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.api.schedule.bo.ScheduleBO;
import com.slipper.system.api.schedule.service.IScheduleSv;
import com.slipper.common.util.ResultUtil;

/**
 * 任务调度
 * 
 * @date 2020-03-28 17:10:06
 */
@RestController
@RequestMapping("/schedule")
public class ScheduleController {
    @Resource
    private IScheduleSv scheduleSv;
    
    @PostMapping("/queryBy")
    public String queryBy(@RequestBody ScheduleBO bo) {
        return ResultUtil.toJson(scheduleSv.queryBy(bo));
    }
    
    @PostMapping("/queryPage")
    public String queryPage(@RequestBody ScheduleBO bo) {
        return ResultUtil.toJson(scheduleSv.queryPage(bo));
    }

    @PostMapping("/save")
    public String save(@RequestBody ScheduleBO bo) {
        return ResultUtil.toJson(scheduleSv.save(bo));
    }

    @PostMapping("/delete")
    public String delete(@RequestBody ScheduleBO bo) {
        return ResultUtil.toJson(scheduleSv.delete(bo));
    }
    
    /**
     * 暂停任务
     *
     */
    @RequestMapping("/pause")
    public String pause(@RequestBody ScheduleBO bo) {
        bo.setStatus(ScheduleBO.STATUS_PAUSE);
        return ResultUtil.toJson(this.scheduleSv.updateStatus(bo));
    }
    
    /**
     * 恢复任务
     *
     */
    @RequestMapping("/resume")
    public String resume(@RequestBody ScheduleBO bo) {
        bo.setStatus(ScheduleBO.STATUS_NORMAL);
        return ResultUtil.toJson(this.scheduleSv.updateStatus(bo));
    }
    
    /**
     * 立即执行任务
     */
    @RequestMapping("/runTask")
    public String runTask(@RequestBody ScheduleBO bo) {
        return ResultUtil.toJson(this.scheduleSv.runTask(bo));
    }
}
